package org.dromara.work.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.ValidatorUtils;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.core.validate.QueryGroup;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.work.domain.bo.SgjBeianReplySaveBo;
import org.dromara.work.domain.bo.SgjBeianSaveBo;
import org.dromara.work.domain.bo.SgjCheckSaveBo;
import org.dromara.work.domain.bo.SgjQueryBo;
import org.dromara.work.domain.vo.SgjBeianVo;
import org.dromara.work.domain.vo.SgjBriefVo;
import org.dromara.work.domain.vo.SgjCheckVo;
import org.dromara.work.service.ISgjBeianService;
import org.dromara.work.service.ISgjCheckService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Calendar;
import java.util.concurrent.TimeUnit;

/**
 * 标准地名
 *
 * @author Chen
 * @date 2024-01-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/work/sgj/beian")
public class SgjBeianController extends BaseController {


    private final ISgjBeianService baseService;



    /**
     * 获取测试单表详细信息
     *
     * @param id 测试ID
     */
    @SaIgnore
    @GetMapping("/{id}")
    public R<SgjBeianVo> getInfo(@NotNull(message = "主键不能为空")
                                 @PathVariable("id") String id) {
        return R.ok(baseService.queryById(id));
    }

    /**
     * 新增测试单表
     */
    @SaIgnore
    @RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS, message = "{repeat.submit.message}")
    @PostMapping()
    public R<Void> add(@RequestBody SgjBeianSaveBo bo) {
        // 使用校验工具对标 @Validated(AddGroup.class) 注解
        // 用于在非 Controller 的地方校验对象
        ValidatorUtils.validate(bo, AddGroup.class);
        return toAjax(baseService.insertByBo(bo));
    }

    /**
     * 新增测试单表
     */
    @SaIgnore
    @RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS, message = "{repeat.submit.message}")
    @PostMapping("/reply")
    public R<Void> addReply(@RequestBody SgjBeianReplySaveBo bo) {
        // 使用校验工具对标 @Validated(AddGroup.class) 注解
        // 用于在非 Controller 的地方校验对象
        ValidatorUtils.validate(bo, AddGroup.class);
        return toAjax(baseService.insertReplyByBo(bo));
    }


    /**
     * 删除测试单表
     *
     * @param ids 测试ID串
     */
    @SaCheckPermission("demo:demo:remove")
    @Log(title = "测试单表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(baseService.deleteWithValidByIds(Arrays.asList(ids), true));
    }



}
